package com.crm.model.dto;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @version 1.0
 * @author: CRM_SYSTEM
 * @date: 2022/3/30 23:34
 * @Description:
 */
@Data
@NoArgsConstructor
public class BasePageResult<T> {
    @ApiModelProperty("数据集")
    private List<T> data;
    @ApiModelProperty("总数量")
    private Long totalNumber;
    @ApiModelProperty("当前页")
    private Long pageNumber;
    @ApiModelProperty("分页大小")
    private Long pageSize;
    @ApiModelProperty("总页数")
    private Long pages;

    public BasePageResult(List<T> data, Long totalNumber) {
        this.data = data;
        this.totalNumber = totalNumber;
    }

    public BasePageResult(List<T> data, Long totalNumber,Long pageNumber,Long pageSize,Long pages) {
        this.data = data;
        this.totalNumber = totalNumber;
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.pages = pages;

    }
    public static <E> BasePageResult<E> newInstance(IPage<E> page) {
        return new BasePageResult<E>(page.getRecords(), page.getTotal(),page.getCurrent(),page.getSize(),page.getPages());
    }

}
